@extends('layouts.base') @section('styles') @parent
<link rel="stylesheet" href="{{asset('assets/plugin/dropify/css/dropify.min.css')}}"> @endsection @section('content') @parent
<div id="wrapper">
	<div class="main-content container">
		<div class="row small-spacing">

			<div class="box-content">
				<h3 class="box-title">分类目录管理</h3>
				<hr>
				<div class="col-md-4">
					<div class="cmodel box-content card" id="editCat">
						<form class="form-horizontal" id="editForm" action="{{route('category.store')}}" method='POST' enctype="multipart/form-data">
							{{ csrf_field() }}
							<h4 class="box-title bg-warning">添加分类</h4>
							<div class="card-content">
								<div class="form-group">
									<label for="cname" class="col-sm-3 control-label">名称</label>
									<div class="col-sm-9">
										<input type="text" name="name" class="form-control" id="cname" placeholder="分类名称" required>
									</div>
								</div>
								<div class="form-group">
									<label for="cslug" class="col-sm-3 control-label">slug</label>
									<div class="col-sm-9">
										<input type="text" name="slug" class="form-control" id="cslug" placeholder="缩略名" required>
									</div>
								</div>
								<div class="form-group">
									<label for="cweight" class="col-sm-3 control-label">权重</label>
									<div class="col-sm-9">
										<input type="text" name="weight" class="form-control" id="cweight" placeholder="数值越大排名在后" required>
									</div>
								</div>
								<div class="form-group text-center">
									<button type="reset" class="btn btn-default waves-effect waves-light">重置</button>
									<button type="submit" id="submit" class="btn btn-primary waves-effect waves-light">添加</button>
								</div>

							</div>
						</form>

					</div>
				</div>
				<div class="col-md-8">
					<div class=" box-content card denger">
						<h4 class="box-title">分类列表</h4>
						<div class="table-responsive">
							<table class="table table-bordered">
								<thead>
									<tr>
										<th class="text-center">#id</th>
										<th class="text-center">分类名称</th>
										<th class="text-center">slug</th>
										<th class="text-center">权重</th>
										<th class="text-center">编辑/删除</th>
									</tr>
								</thead>
								<tbody>
									@foreach($cats as $cat)
									<tr>
										<th scope="row">{{$cat->id}}</th>
										<td>{{$cat->name}}&nbsp;({{$cat->words()->count()}})</td>
										<td>{{$cat->slug}}</td>
										<td>{{$cat->weight}}</td>
										<td class="text-right">
											<button type="button" class="showedit btn btn-info btn-xs waves-effect waves-light" data-id="{{$cat->id}}" data-name="{{$cat->name}}" data-slug="{{$cat->slug}}" data-weight="{{$cat->weight}}" data-url="{{route('category.update',$cat->id)}}">编辑</button>
											<form action="{{route('category.destroy',$cat->id)}}" method="post" style="display: inline-block;">{{ csrf_field() }}{{ method_field('DELETE') }}<button type="submit" class="btn btn-orange btn-xs waves-effect waves-light">删除</button>
											</form>
										</td>
									</tr>
									@endforeach
								</tbody>
							</table>
						</div>
					</div>
				</div>

			</div>
			<!--.box-content-->
		</div>
		<!--.small-spacing-->
	</div>
</div>
<!--#wrapper-->
@endsection @section('scriptsafter') @parent
<script>
	$(".showedit").on('click', function (e) {
		var button = $(e.target)
		var cid = button.data('id')
		var cname = button.data('name')
		var cslug = button.data('slug')
		var cweight = button.data('weight')
		var curl = button.data('url')
		var modal = $('#editCat')
		$("#editForm").attr("action", curl);
		$("#editForm").prepend('<input type="hidden" name="_method" value="PATCH">');
		modal.find('.box-title').text('修改id为' + cid + '的分类')
		modal.find('.card-content input#cname').val(cname)
		modal.find('.card-content input#cslug').val(cslug)
		modal.find('.card-content input#cweight').val(cweight)
	});
</script>

@endsection